package com.eeepay.eeepay_v2.activity;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import com.eeepay.eeepay_v2.R;
import com.eeepay.eeepay_v2.adapter.CJTTabAdapter;
import com.eeepay.eeepay_v2.api.GetSuperPushShareCountAPI;
import com.eeepay.eeepay_v2.fragment.CjtInComeRecordFragment;
import com.eeepay.eeepay_v2.fragment.GetInvPriMerInfoRecordFragment;
import com.eeepay.eeepay_v2.model.UserInfo;
import com.eeepay.v2_library.ui.ABBaseActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * 描述：超级推收益查询入口
 * 作者：zhuangzeqin
 * 时间: 2017/7/20-14:14
 * 邮箱：zzq@eeepay.cn
 */
public class CjtInComeActivity extends ABBaseActivity implements View.OnClickListener {
    private TextView tv_todayincome;//今日收益
    private TextView tv_grandtotal;//累计收益
    private GetSuperPushShareCountAPI mGetSuperPushShareCountAPI;//获取超级推分润统计 今日收益统计 or 累计收益
    private TabLayout tab_layout;
    private ViewPager viewpager;
    private List<Fragment> mFragmentTab;
    private CJTTabAdapter adapter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_cjt_in_come;
    }

    @Override
    protected void initWidget() {
        tv_todayincome = getViewById(R.id.tv_todayincome);
        tv_grandtotal = getViewById(R.id.tv_grandtotal);
        tab_layout = getViewById(R.id.tab_layout);
        viewpager = getViewById(R.id.viewpager);
        initTab();
    }

    private void initTab() {
        mFragmentTab = new ArrayList<>();
        mFragmentTab.add(CjtInComeRecordFragment.getInstance());//交易记录
        adapter = new CJTTabAdapter(getSupportFragmentManager());
        //一级代理商才有邀请好友奖励记录查询
        if ("1".equals(UserInfo.getUserInfo2SP().getAgentLevel())) {
            mFragmentTab.add(GetInvPriMerInfoRecordFragment.getInstance());//邀请好友奖励
            tab_layout.setVisibility(View.VISIBLE);
        } else {
            tab_layout.setVisibility(View.GONE);
        }
        adapter.setListFragments(mFragmentTab);
        viewpager.setAdapter(adapter);
        viewpager.setOffscreenPageLimit(1);
//        viewpager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tab_layout));
        tab_layout.setupWithViewPager(viewpager);//关联viewPage
        tab_layout.setTabGravity(TabLayout.GRAVITY_FILL);
        tab_layout.setTabMode(TabLayout.MODE_FIXED);
    }

    /**
     * 获取tab 选中的索引值
     * @return
     */
    public int gettabPosition()
    {
        if (tab_layout!=null)
            return tab_layout.getSelectedTabPosition();
        else
            return 0;
    }


    @Override
    protected void eventOnClick() {
        reqSuperPushShareCount();
    }

    /**
     * 获取 今日收益统计 && 累计收益
     */
    private void reqSuperPushShareCount() {
        mGetSuperPushShareCountAPI = new GetSuperPushShareCountAPI();
        mGetSuperPushShareCountAPI.setResultCallBack(new GetSuperPushShareCountAPI.ResultCallBack() {
            @Override
            public void onFail(String msg) {
                showToast(msg);
            }

            @Override
            public void onSucess(String todayCount, String allCount) {
                tv_todayincome.setText(todayCount);
                tv_grandtotal.setText(allCount);
               // NumAnimUtil.startAnim(tv_todayincome, MathUtils.String2Float(todayCount), 1000);// add by zhuangzeqin 2017年7月25日10:45:33 滚动效果
               // NumAnimUtil.startAnim(tv_grandtotal, MathUtils.String2Float(allCount), 1000);// add by zhuangzeqin 2017年7月25日10:45:33 滚动效果
            }
        });
        mGetSuperPushShareCountAPI.getSuperPushShareCountInfo();
    }

    /**
     * 开始网络请求
     *
     * @param taskId
     */
    @Override
    protected void sendHttpRequest(int taskId) {
    }

    @Override
    public void onClick(View v) {

    }
}
